#!/usr/bin/env python

# --------------------------------------
# project2 : TestPrimes.py
# Fransiscus Evan Gumulya
# feg247
# --------------------------------------

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        """
        read the input
        """
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        """
        writes something to the console / file
        """
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestPrimes
# -----------

class TestPrimes (unittest.TestCase) :
    # ----
    # read
    # ----

    def test_read (self) :
        """
        test to read 1 from input
        """
        reader = TestReader('1\n')
        main.my_read(reader)
        self.assert_(main.i ==  1)

    def test_read2 (self):
        """
        test to read 2000 from input
        """
        reader = TestReader('2000\n')
        main.my_read(reader)
        self.assert_(main.i == 2000)

    # ----
    # eval
    # ----

    def test_eval1 (self) :
        """
        test the primes calculation with i = 8
        """
        main.i =  8
        main.my_eval()
        self.assert_(main.p1 == 2)
	self.assert_(main.p2 == 2)
	self.assert_(main.p3 == 2)
	self.assert_(main.p4 == 2)

    def test_eval2 (self) :
        """
        test the primes calculation with i = 99
        """
        main.i =  99
        main.my_eval()
        self.assert_(main.p1 == 2) 
        self.assert_(main.p2 == 3) 
        self.assert_(main.p3 == 5) 
        self.assert_(main.p4 == 89) 

    def test_eval3 (self) :
        """
        test the primes calculation with i = 12345
        """
        main.i =  12345
        main.my_eval()
        self.assert_(main.p1 == 2) 
        self.assert_(main.p2 == 3) 
        self.assert_(main.p3 == 11) 
        self.assert_(main.p4 == 12329)

    def test_eval4 (self) :
        """
        test the primes calculation with i = 22
        """
        main.i =  22
        main.my_eval()
        self.assert_(main.p1 == 2) 
        self.assert_(main.p2 == 2) 
        self.assert_(main.p3 == 5) 
        self.assert_(main.p4 == 13)

    def test_eval5 (self) :
        """
        test the primes calculation with i = 564332
        """
        main.i =  564332
        main.my_eval()
        self.assert_(main.p1 == 2)
        self.assert_(main.p2 == 2)
        self.assert_(main.p3 == 5)
        self.assert_(main.p4 == 564323)

    def test_eval6 (self) :
        """
        test the primes calculation with i = 98765
        """
        main.i =  98765
        main.my_eval()
        self.assert_(main.p1 == 2)
        self.assert_(main.p2 == 3)
        self.assert_(main.p3 == 23)
        self.assert_(main.p4 == 98737)

    def test_eval7 (self) :
        """
        test the primes calculation with i = 999999
        """
        main.i =  999999
        main.my_eval()
        self.assert_(main.p1 == 2)
        self.assert_(main.p2 == 3)
        self.assert_(main.p3 == 11)
        self.assert_(main.p4 == 999983)

    def test_eval8 (self) :
        """
        test the primes calculation with i = 745680
        """
        main.i =  745680
        main.my_eval()
        self.assert_(main.p1 == 2)
        self.assert_(main.p2 == 2)
        self.assert_(main.p3 == 3)
        self.assert_(main.p4 == 745673)     
 
    # -----
    # print
    # -----

    def test_print1 (self) :
        """
        test to print with p1 = 10, p2 = 20, p3 = 30, p4 = 40
        """
        main.p1 = 10
        main.p2 = 20
        main.p3 = 30
        main.p4 = 40
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == '10 20 30 40\n')

if __name__ == "__main__" :
    unittest.main()



